package com.qhit.dao.impl;

import com.qhit.dao.BaseDao;
import com.qhit.dao.StudentDao;
import com.qhit.entity.Student;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.util.List;

/**
 * TODO
 *
 * @author 村头老杨头
 * @version 1.0
 * @date 2021/10/12 15:19
 */
public class StudentDaoImpl extends BaseDao implements StudentDao {
    @Override
    public List<Student> getStudentList() {
        String sql = "select * from student";
        return query(sql,new BeanListHandler<Student>(Student.class));
    }

    @Override
    public Student getStudentById(String sno) {
        String sql = "select * from student where sno=?";
        return query(sql,new BeanHandler<Student>(Student.class),sno);
    }

    @Override
    public int addStudent(Student student) {
        String sql = "insert into student  values (?,?,?,?,?)";
        return update(sql,student.getSno(),student.getSname(),student.getSsex(),student.getSbirthday(),student.getClazz());
    }

    @Override
    public int deleteStudent(String sno) {
        String sql = "delete from student where sno=?";
        return update(sql,sno);
    }

    @Override
    public int updateStudent(Student student) {
        String sql = "update student set  sname=?,ssex=?,sbirthday=?,clazz=? where sno=?";
        return update(sql,student.getSname(),student.getSsex(),student.getSbirthday(),student.getClazz(),student.getSno());
    }
}
